package logica.funciones;

public class Funciones {
	private static final double e = Math.E;
	private static final double pi = Math.PI;
	public static final double  ERROR_ENTRADA = Double.NEGATIVE_INFINITY;
			
	//Los valores mdevueltos mejor excepciones
    public static double fx1Practica1(double x){
    	double res;
    	
    	if (x>=0 && x<=32){
    		double sumando2, sumando3;
    		sumando2 = e - 20 * Math.pow(e, -0.2 * Math.abs(x));
    		sumando3 = Math.pow(e, Math.cos(2*pi * x));
    		
    		res = 20 + sumando2 - sumando3; 
    	} else 
    		res = ERROR_ENTRADA; 
    	
    	return res;
    } // fx1Practica1
    
    
    public static double fx2Practica1(double x, double y){
    	double termino2, termino3, res;
    	
    	if ((x>=-3.0 && x<=12.1) && (y>=4.1 && y<=5.8)){
    		termino2 = x*Math.sin(4*pi*x);
    		termino3 = y*Math.sin(20*pi*y);
    		res = 21.5 + termino2 + termino3;
    	} else 
    		res = ERROR_ENTRADA;
    		
    	return res; 
    } // fx2Practica1

    
    public static double fx3Practica1(double x){
	   double anguloRad, res;
	   
	   if (x>=-250 && x<=250){
		   anguloRad = Math.sqrt(Math.abs(x));
		   
		   res = -1 * Math.abs(x * Math.sin(anguloRad));
  
	   } else 
   		   res = ERROR_ENTRADA;
	   
	   return res;
    } // fx3Practica1

    public static double fx4Practica1(double x[]){
    	int nXs = x.length, i;
    	boolean error = false;
    	double res = 0.0;
    	
    	i = 0;
    	while (i < nXs && error == false){
    	   if (x[i]>=0 && x[i]<=100)	
    	      res += (-1 * x[i] * Math.sin(Math.abs(x[i])));
    	      else error = true;  
           i++;    		
    	}
    		
    	if (error)
    		res = ERROR_ENTRADA;
    	
    	return res;
  
    } // fx4Practica1
    
    public static double fx5Practica1(double x[]){
	      double res = 0.0, angRadianes;
	      int i = 0, numEls = x.length;
	      boolean error = false;
	      double fact1, fact2;
	      double x1, x2;
	      
	      if (x.length != 2)
	    	  error = true;
	      else {
	         x1 = x[0]; x2 = x[1];
	         if ((x1>=-10 && x1<=10) && (x2>=-10 && x2<=10)){
	    	    fact1 = 0; fact2 = 0;
	    	    for (i=1; i<=5; i++){
	    	       fact1+=(i * Math.cos((i+1)*x1+i));
	    	       fact2+=(i * Math.cos((i+1)*x2+i));
	    	    }
	    	    res = fact1 * fact2;
	         }else error = true;
	      }
	      
	      if (error)
	          res = ERROR_ENTRADA;
	      
	      return res;
	      
  } // fx5Practica1

}
